import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';

import '../../../router/route_map.dart';

/// 表格演示主界面
class ChartPage extends StatelessWidget {
  const ChartPage({super.key});

  /// 菜单布局
  Widget gridMenuItem(String menuName, GestureTapCallback? onTap) {
    return InkWell(
      onTap: onTap,
      child: Container(
        color: Colors.white,
        padding: const EdgeInsets.all(10),
        child: Text(
          menuName,
          style: const TextStyle(
            fontWeight: FontWeight.bold,
            color: Colors.black,
            fontSize: 20,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('图表演示'),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          color: Colors.white,
          onPressed: Get.back,
        ),
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return GridView.count(
      crossAxisCount: 2,
      scrollDirection: Axis.vertical,
      //宽高比
      childAspectRatio: 2 / 1,
      padding: const EdgeInsets.all(12),
      mainAxisSpacing: 12,
      crossAxisSpacing: 12,
      children: [
        gridMenuItem('折线图', () {
          RouteMap.goLineChartPage();
        }),
        gridMenuItem('柱状图', () {
          RouteMap.pushBarChartPage();
        }),
        gridMenuItem('组合图', () {
          RouteMap.pushCombinedChartPage();
        }),
        gridMenuItem('横向柱状图', () {
          RouteMap.pushHorizontalBarChartPage();
        }),
        gridMenuItem('饼状图', () {
          RouteMap.pushPieChartPage();
        }),
        gridMenuItem('3D饼状图', () {
          RouteMap.pushPieChart3DPage();
        }),
        gridMenuItem('雷达图', () {
          RouteMap.pushRadarChartPage();
        }),
      ],
    );
  }
}
